// pages/Generalreservation/Generalreservation.js
var app = getApp();
Page({
  onLoad: function (e) {
    var that = this;
    if (e && e.enterfrom) {
      var enterfrom = e.enterfrom == 'share' ? true : false;
      that.setData({
        enterfrom: enterfrom
      })
    }
  },
  onShow: function () {
    var that = this;
    if (!app.globalData.plumSession) {
      app.wechatSq(that);
    }else{
      that.loadData();
      app.contactData(that); 
    }
    if(that.data.title){
      app.setNavtitle(that.data.title);
    }
    app.setCartnum();//更新购物车数量
  },
  // 客服回复组件间传值
  getreplyData: function (e) {
    console.log(e.detail);
    this.setData(e.detail);
  },
  onPullDownRefresh: function () {
    var that = this;
    that.loadData();
  },
  loadData: function () {
    var that = this;
    if (!that.data.info) {
      wx.showLoading({
        title: '加载中...',
      })
    }
    wx.request({
      // url: app.globalData.requestUrl,
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_appointment_index'
      },
      
      success: function (res) {
        console.log(res)
        if (res.data.ec == 200) {
          that.setData({
            info: res.data.data,
            title: res.data.data.template.title
          })
          app.setNavtitle(res.data.data.template.title);
          app.globalData.mustAddress = res.data.data.mustAddress;
          app.globalData.mustTime = res.data.data.mustTime;
          
        } else {

        }
      },
      fail: function () {
        console.log("fail")
      },
      complete: function () {
        wx.hideLoading()
        wx.stopPullDownRefresh()
      }
    })
  },
  noteableClick: function (e) {
    if(!app.globalData.plumSession) {
      app.wechatSq();
      return;
    }
    var id = e.currentTarget.dataset.id;
    if (id == 0) {
      return;
    }
    wx.navigateTo({
      url: '/subpages1/informationDetail/informationDetail?id=' + id + "&title=" + e.currentTarget.dataset.title,
    })
  },
  cellClick: function (e) {
    if (!app.globalData.plumSession) {
      app.wechatSq();
      return;
    }
    var id = e.currentTarget.dataset.id;
    if (!id || id.length == 0) {
      return;
    }
    wx.navigateTo({
      url: '/subpages/Generalreservationdetail/Generalreservationdetail?id=' + id,
    })
  },
  myorderClick: function (e) {
    if (!app.globalData.plumSession) {
      app.wechatSq();
      return;
    }
    var title = e.currentTarget.dataset.title; 
    wx.navigateTo({
      url: '/subpages/Generalreservationlist/Generalreservationlist?title='+title,
    })
  },
  makeCall:function(e){
    var mobile = e.currentTarget.dataset.mobile;
    app.makeCallphone(mobile);
  },
  seemap: function (e) {
    var latitude = e.currentTarget.dataset.lat;
    var longitude = e.currentTarget.dataset.lng;
    var address = e.currentTarget.dataset.address;
    var name = e.currentTarget.dataset.name;
    wx.openLocation({
      latitude: Number(latitude),
      longitude: Number(longitude),
      name: name,
      address: address,
      scale: 18
    })
  },
  //打开更多预约项目
  openMoreProject:function(){
    wx.navigateTo({
      url: '/subpages/GeneralreservationProject/GeneralreservationProject',
    })
  },
  seeDetail: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/subpages1/informationDetail/informationDetail?id=' + id
    })
  },
  //转发
  onShareAppMessage: function () {
    var that = this;
    var title = app.name;
    var shareInfo = app.globalData.shareInfo;
    title = shareInfo.shareTitle ? shareInfo.shareTitle : title;
    var cover = shareInfo.shareCover ? shareInfo.shareCover : '';
    app.getPoint(that);
    return {
      title: title,
      imageUrl: cover,
      path: '/pages/Generalreservation/Generalreservation?enterfrom=share'
    }
  }
})